package com.jic.manager.impl;

import com.jic.common.base.vo.PageResult;
import com.jic.manager.mapper.SysCarouselFigureMapper;
import com.jic.manager.entity.SysCarouselFigure;
import com.jic.conf.request.SysCarouselFigureRequest;
import com.jic.manager.service.SysCarouselFigureService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 轮播图管理
 * @author : 
 * @email : 
 * @since : 2020-02-26 01:51:48
 * @version : v1.0.0
 */
@Service
public class SysCarouselFigureServiceImpl implements SysCarouselFigureService{

    @Autowired
    private SysCarouselFigureMapper sysCarouselFigureMapper;

    @Override
    public long insert(SysCarouselFigureRequest request) {
        SysCarouselFigure sysCarouselFigure = new SysCarouselFigure();
        BeanUtils.copyProperties(request,sysCarouselFigure);
        sysCarouselFigure.setDeptId(request.getAdminOperate().getDeptId());
        sysCarouselFigure.setCreator(null!=request.getAdminOperate()?request.getAdminOperate().getOperator():0);
        sysCarouselFigure.setCreatorName(null!=request.getAdminOperate()?request.getAdminOperate().getOperateName():"");
        return sysCarouselFigureMapper.insert(sysCarouselFigure);
    }

    @Override
    public long delete(Long id) {
        return sysCarouselFigureMapper.delete(id);
    }

    @Override
    public long update(SysCarouselFigureRequest request) {
        SysCarouselFigure sysCarouselFigure = new SysCarouselFigure();
        BeanUtils.copyProperties(request,sysCarouselFigure);
        sysCarouselFigure.setUpdater(null!=request.getAdminOperate()?request.getAdminOperate().getOperator():0);
        sysCarouselFigure.setUpdaterName(null!=request.getAdminOperate()?request.getAdminOperate().getOperateName():"");
        return sysCarouselFigureMapper.update(sysCarouselFigure);
    }

    @Override
    public SysCarouselFigure queryByPrimaryKey(Long id){
        return sysCarouselFigureMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<SysCarouselFigure> query(SysCarouselFigureRequest request){
        SysCarouselFigure sysCarouselFigure = new SysCarouselFigure();
        BeanUtils.copyProperties(request,sysCarouselFigure);
        sysCarouselFigure.setDeleteFlag(0L);
        return sysCarouselFigureMapper.query(sysCarouselFigure);
    }

    @Override
    public PageResult<SysCarouselFigure> queryPage(SysCarouselFigureRequest request) {
        //计算下标
        int startIndex = (request.getStart() - 1) * request.getLimit();
        List<SysCarouselFigure> list = sysCarouselFigureMapper.queryPage(startIndex, request.getLimit(), request);
        long count = sysCarouselFigureMapper.queryPageCount(request);
        PageResult<SysCarouselFigure> pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}